<div class="main_fr_mic" style="margin-bottom:10px;">
          <i class="glyphicon glyphicon-home"></i>
          <a href="admin/index">首页</a><span>></span>
          <a  class="active">实验室管理</a><span>></span>
          <a class="active">实验室</a>
</div>
 
<div id="interfaceList" class="main_fr_down over">
	<div class="main_fr_search over mb10">
		  <form id="search_submit" class="form-inline">
			  <div class="good_top22">
				  <span class="good_top021">条件查询</span>
			  </div>
			  <div class="main_fr_search_cx">
				实验室名称<input name="lab.name" placeholder="请输入实验室名称" type="text" class="srk" style="width:200px;"/>
				状态<select name="lab.status" class="srk" style="width:200px;">
	              		<option value="1">开启</option>
	              		<option value="0">禁用</option>
	              	</select>
	              	<input type="button" onclick="search(1);" class="search_an01 anbg" value="查询">			  
			  </div>
		  </form>
	</div>
	<div class="sh_search over mb10">
		<div class="over sh_search_table">
		<div class="over mb10" style=" position:relative;">
			<div class="good_top22" style="margin-bottom: 0px;">
			  <span class="good_top021">实验室列表</span>
			  <span class="good_top022">
			 <!--  link/update'-->
				 	<input type="button" onclick="update(0);" class="search_an01" value="新增">
				 <!--  -->
			   </span>
			 </div>
		</div> 
	</div>
	<table class="table table-bordered table-hover">
		<thead  class="table_heaer">
			<tr class="text-center">
			<th>编号</th>
				<th>实验室名称</th>
				<th>更新时间</th>
				<th>状态</th>
				<th>操作</th> 
			</tr>
		</thead>
		<tbody id="projectTable">
		</tbody>
	</table>
	</div>
		<div id="pages" class="text-right"></div>	
	</div>
<!--  弹出层div-->
<div id="addFormDiv" class="hide" style="padding-top:15px;">
	<form class="form-horizontal" id="addForm">
		<input type="hidden" id="id" name="lab.id">
		<div class="form-group">
			<label for="inputEmail3" class="col-sm-2 control-label">实验室名称</label>
			<div class="col-sm-9">
				<input type="text"  class="form-control" id="name" placeholder="请输入实验室名称" name="lab.name" minlength="1"  maxlength="20" required>
			</div>
		</div>
		<div class="form-group">
			<label for="inputEmail3" class="col-sm-2 control-label">地址</label>
			<div class="col-sm-9">
				<input type="text"  class="form-control" id="address" placeholder="请输入实验室地址" name="lab.address" minlength="1"  maxlength="100" required>
			</div>
		</div>
		<div class="form-group">
			<label for="inputEmail3" class="col-sm-2 control-label">管理员</label>
			<div class="col-sm-9">
				<input type="text"  class="form-control" id="manager" placeholder="请输入管理员姓名" name="lab.manager" minlength="1"  maxlength="20" required>
			</div>
		</div>
		<div class="form-group">
			<label for="inputEmail3" class="col-sm-2 control-label">联系方式</label>
			<div class="col-sm-9">
				<input type="text"  class="form-control" id="tel" placeholder="请输入管理员联系方式" name="lab.tel" minlength="1"  maxlength="30" required>
			</div>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail2" class="col-sm-2 control-label">备注信息</label>
			<div class="col-sm-9">
				<textarea rows="5" style="width:100%" id="des" name="lab.des" placeholder="请输入备注信息"></textarea>
			</div>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail2" class="col-sm-2 control-label">状态</label>
			<div class="col-sm-9">
			<select id="status" name="lab.status" class="form-control" style="width:200px;">
              		<option value="1">开启</option>
              		<option value="0">禁用</option>
              	</select>
			</div>
		</div>
		<div class="form-group">
		<label for="exampleInputEmail2" class="col-sm-2 control-label"></label>
			<div class="col-sm-9">
			<button type="submit" class="btn btn-success">立即提交</button>
			<button type="reset" class="btn btn-default">重置</button>
			</div>
		</div>
		
	</form>
</div>
<!-- 在这里引入本页面需要的js -->
<script>
function userList(data) {
	var dataStr = "";
	$.each(data, function(i, v) {
		if(v.description==null){
			v.description=="";
		}
		dataStr += '<tr>';
		dataStr += '<td>' + v.id + '</td>';
		dataStr += '<td>' + v.name + '</td>';
		dataStr += '<td>' + v.update_time + '</td>';
		if(v.status==0){
			dataStr += '<td>禁用</td>';
		}else if(v.status==1){
			dataStr += '<td>开启</td>';
		}
		dataStr += '<td>';
			 @@if (ac(session.userId, 'lab/update')){
				dataStr += '<a href="javaScript:update(' + v.id + ');" class="btn btn-default">' + '编辑' + '</a>';
			@@}
			@@if (ac(session.userId, 'lab/del')){
				dataStr += '<a recordId="' + v.id + '" class="btn btn-default deleteButton">' + '删除' + '</a>';
			@@}
		dataStr += '</td>'; 
		dataStr += '</tr>';
	});
	$("#projectTable").html(dataStr);
	$("#projectTable .deleteButton").click(function() {
		clickDelete($(this));
		return false;
	})
}
var cc=1;
function pageChange(curr) {
	$.get("lab/list?curr="+curr, $("#search_submit").serialize(), function(data) {
		userList(data.content.list);
		laypage({
		    cont: $('#pages'), //容器。值支持id名、原生dom对象，jquery对象,
		    pages: data.content.totalPage, //总页数
		    skip: true, //是否开启跳页
		    skin: '#4599e0',
		    curr: data.content.pageNumber,
		    groups: 3, //连续显示分页数
		    jump: function(obj, first) {
		    	if(!first){ //一定要加此判断，否则初始时会无限刷新
		    		cc=obj.curr;
		    		pageChange(obj.curr);
		    	}
		    }
		});
	});
}
pageChange(1);
function search(curr){
	if(curr != 1){
		curr=cc;
	}
	pageChange(curr);
}
var index;
var validator;
$().ready(function() {
	 validator = $("#addForm").validate({
	        submitHandler:function(form){
	        	$.post('lab/update', $("#addForm").serialize(), function(data){
	        		if(data.code==0){
	        			layer.msg("保存成功！");
	        			layer.close(index);
	        			search(cc);
	        		}else{
	        			layer.msg("保存失败,名称不能重复！");
	        			return false;
	        		}
	        	}) 
	        }    
	    });
	    $("#reset").click(function() {
	        validator.resetForm();
	    });
	});
function update(id) {
	var tit = "新增实验室信息";
	if(id != 0){
		$.post("lab/getInfo",{id:id},function(data){
			if(data.code==0){
				for (var key in data.content){
					$("#"+key).val(data.content[key]);
				}
			}else{
				layer.msg("获取信息失败！");
				return false;
			}
		})
		tit = "修改实验室信息";
	}else{
		document.getElementById("addForm").reset();
		$("#id").val("");
		$("#image_path").html("");
	} 
 	$("#addFormDiv").removeClass("hide");
	index=layer.open({
		type : 1,
		area: ['40%','60%'],
		title : tit,
		content : $("#addFormDiv"),
		
		cancel: function(index, layero) {
			 validator.resetForm();//// 重置表单验证提示
			    
			$("#addFormDiv").addClass("hide");
			layer.close(index);
		} 
	})
};
function clickDelete(obj) {
	// 给删除按钮注册事件
	// 获取当前记录的信息写入
	if(confirm("确定要删除该实验室吗？")){
		var recordId = obj.attr("recordId");
		$.get("lab/del", {"id":recordId}, function(data) {
			if (data.code == 0) {
				obj.closest("tr").remove();
				layer.msg("删除成功！");
			}else{
				layer.msg("删除失败！");
				return false;
			} 
		})
	}
}
</script>